package controlLayer;
import modelLayer.*;

import java.util.ArrayList;


public class ItemController{
    
   private ItemContainer itemContainer;
    
    public ItemController()    {
        itemContainer = ItemContainer.getInstance();       
    }

   
    public Item findItem(int barcode)
    {
        ArrayList<Item> items = ItemContainer.getInstance().getAllItems();
        for(Item i : items){
            if(i.getBarcode()==barcode)
                return i;
        }
        return null;
    }
    
    public boolean checkQuantity(int barcode, int quantity){
        Item item = findItem(barcode);
        if(item.getQuantity() >= quantity)
            return true;
        return false;
    }
    public int makeSetQuantity(int barcode){
    	int q=9999;
    	for(Item item: ItemContainer.getInstance().getAllItems()){
    		if(item.getBarcode()==barcode)
    		{
    		q=9999;
    		for(Integer i: ((Set) item).getSetItems())	{
    			if(q>findItem(barcode).getQuantity()) q=findItem(barcode).getQuantity();
    		}
    		}
    	
    	}
    	return  q;
    }
}
